/*
    This file is part of the Time-of-Flight Tracer program. It is not part of
    the original PBRT source distribution. See the included license file for
    more information.

    Copyright(c) 2014 Microsoft Corporation

    Author: Phil Pitts
*/


#include "stdafx.h"
#include "film/backscatter.h"


BackscatterFilm::BackscatterFilm(int xres, int yres, const string &fn) : Film(
	xres, yres, fn) {
}

BackscatterFilm::~BackscatterFilm() {
}


void BackscatterFilm::GetSampleExtent(int *xstart, int *xend,
	int *ystart, int *yend) const {
	*xstart = 0;
	*xend = xResolution;
	*ystart = 0;
	*yend = yResolution;
}


void BackscatterFilm::GetPixelExtent(int *xstart, int *xend,
	int *ystart, int *yend) const {
	*xstart = 0;
	*xend = xResolution;
	*ystart = 0;
	*yend = yResolution;
}


void BackscatterFilm::UpdateDisplay(int x0, int y0, int x1, int y1,
	float splatScale) {
}


HistogramSample* BackscatterFilm::GetHistogramSample(const CameraSample &sample) {
	CameraSample *cameraSample = const_cast<CameraSample*>(&sample);
	HistogramSample *hSample = dynamic_cast<HistogramSample*>(cameraSample);
	if (!hSample) {
		Warning("Sample provided to Backscatter film has no histogram data.");
	}
	return hSample;
}


void GetBackscatterParams(ParamSet params, int *xres, int *yres,
	string *filename) {
	// Intentionally use FindOneString() rather than FindOneFilename() here
	// so that the rendered image is left in the working directory, rather
	// than the directory the scene file lives in.
	*filename = params.FindOneString("filename", "");
	if (PbrtOptions.imageFile != "") {
		if (*filename != "") {
			Warning("Output filename supplied on command line, \"%s\", ignored "
				"due to filename provided in scene description file, \"%s\".",
				PbrtOptions.imageFile.c_str(), filename->c_str());
		}
		else *filename = PbrtOptions.imageFile;
	}
	if (*filename == "") *filename = "output.txt";

	*xres = params.FindOneInt("xresolution", 640);
	*yres = params.FindOneInt("yresolution", 480);
	if (PbrtOptions.quickRender) *xres = max(1, *xres / 4);
	if (PbrtOptions.quickRender) *yres = max(1, *yres / 4);
}